package com.ch.web.controller;

import com.ch.web.ResponseDto.xyGz.XyGzFsCountResponse;
import com.ch.web.entity.user.XyGzEntity;
import com.ch.web.requestDto.xyGzRequest.XyGzFsRequest;
import com.ch.web.service.XyGzService;
import com.ch.web.utils.PageUtils;
import com.ch.web.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 * @author chenHao
 * @email 1429542285@qq.com
 * @date 2022-10-16 15:44:28
 */
@RestController
@RequestMapping("xy/gz")
public class XyGzController {
    @Autowired
    private XyGzService xyGzService;


    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = xyGzService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{followersId}")

    public R info(@PathVariable("followersId") Long followersId) {
        XyGzEntity xyGz = xyGzService.getById(followersId);

        return R.ok().put("xyGz", xyGz);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody XyGzEntity xyGz, HttpServletRequest request) {
        return xyGzService.save(xyGz, request) ? R.ok() : R.error("服务器繁忙");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody XyGzEntity xyGz) {
        xyGzService.updateById(xyGz);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] followersIds) {
        xyGzService.removeByIds(Arrays.asList(followersIds));
        return R.ok();
    }

    /**
     * 取消关注
     */
    @PostMapping("/cancelGz")
    public R cancelGz(@RequestBody XyGzEntity xyGzEntity,HttpServletRequest request){
        return xyGzService.cancelGz(xyGzEntity,request);
    }
    /**
     * 根据用户id获取用户的关注了多少人
     */
    @PostMapping("/getUserGzById")
    public R getUserGzById(@RequestBody XyGzEntity xyGzEntity){
        return xyGzService.getUserGzCount(xyGzEntity);
    }
    /**
     * 根据用户id获取用户的粉丝数多少人
     */
    @PostMapping("/getUserFsById")
    public R getUserFsById(@RequestBody XyGzFsRequest xyGzFsRequest){
        XyGzFsCountResponse gzFsCountResponse=xyGzService.getUserFsCount(xyGzFsRequest);
        return R.ok().put("gzFsResp",gzFsCountResponse);
    }
}
